<?php
/**
 * Created by PhpStorm.
 * User: dingding
 * Date: 2017/8/9
 * Time: 10:29
 */

class RandomResponse{

    private $response=array("渐入佳境", "给你一个大拇指！", "恭喜你已经成为xx领域的专家了", "我也就是抛个砖",
        "未来是人机物融合的世界！", "你去问ta, ta是这方面的专家", "冰冻三尺非一日之寒", "我们的三驾马车三道闪电就是软工未来的发展趋势！",
        "哲学是望远镜，数学是显微镜。", "等你把这个做好，我们可以做很多事，那就是一系列的文章，而不是仅仅一篇文章了");

    public function getRandomResponse(){
        $index = array_rand($this->response);
        if($index == 0 || $index == 1 || $index == 2){
            return $this->response[$index].$this->bytes_to_emoji(0x1F44D);
        } else {
            return $this->response[$index];
        }
    }

    //字节转Emoji表情
    public function bytes_to_emoji($cp)
    {
        if ($cp > 0x10000){       # 4 bytes
            return chr(0xF0 | (($cp & 0x1C0000) >> 18)).chr(0x80 | (($cp & 0x3F000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
        }else if ($cp > 0x800){   # 3 bytes
            return chr(0xE0 | (($cp & 0xF000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
        }else if ($cp > 0x80){    # 2 bytes
            return chr(0xC0 | (($cp & 0x7C0) >> 6)).chr(0x80 | ($cp & 0x3F));
        }else{                    # 1 byte
            return chr($cp);
        }
    }
}
?>